<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
  <head>
    <th:block th:include="include :: header('新增云游展厅')" />
    <th:block th:include="include :: bootstrap-fileinput-css" />
  </head>
  <body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
      <form class="form-horizontal m" id="form-exhibition-add">
        <div class="form-group">
          <label class="col-sm-3 control-label">展厅标题：</label>
          <div class="col-sm-8">
            <input name="title" class="form-control" type="text" required />
          </div>
        </div>
        <div class="form-group">
          <label class="col-sm-3 control-label">展厅介绍：</label>
          <div class="col-sm-8">
            <textarea
              name="description"
              id="description"
              class="form-control"
              rows="6"
              placeholder="请输入展厅介绍"
            ></textarea>
          </div>
        </div>
        <div class="form-group">
          <label class="col-sm-3 control-label">封面图片：</label>
          <div class="col-sm-8">
            <input type="hidden" name="coverUrl" />
            <div class="file-loading">
              <input
                class="form-control file-upload"
                id="coverUrl"
                name="file"
                type="file"
                accept="image/*"
              />
            </div>
            <span class="help-block m-b-none"
              ><i class="fa fa-info-circle"></i> 请上传展厅封面图片</span
            >
          </div>
        </div>
        <div class="form-group">
          <label class="col-sm-3 control-label">视频文件：</label>
          <div class="col-sm-8">
            <input type="hidden" name="videoUrl" />
            <div class="file-loading">
              <input
                class="form-control file-upload"
                id="videoUrl"
                name="file"
                type="file"
                accept="video/*"
              />
            </div>
            <span class="help-block m-b-none"
              ><i class="fa fa-info-circle"></i> 请上传视频文件</span
            >
          </div>
        </div>
        <div class="form-group">
          <label class="col-sm-3 control-label">状态：</label>
          <div class="col-sm-8">
            <div
              class="radio-box"
              th:each="dict : ${@dict.getType('sys_normal_disable')}"
            >
              <input
                type="radio"
                th:id="${dict.dictCode}"
                name="status"
                th:value="${dict.dictValue}"
                th:checked="${dict.default}"
              />
              <label
                th:for="${dict.dictCode}"
                th:text="${dict.dictLabel}"
              ></label>
            </div>
          </div>
        </div>
      </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: bootstrap-fileinput-js" />
    <script type="text/javascript">
      var prefix = ctx + "hui/interact/exhibition";

      $("#form-exhibition-add").validate({
        focusCleanup: true,
      });

      function submitHandler() {
        if ($.validate.form()) {
          $.operate.save(
            prefix + "/add",
            $("#form-exhibition-add").serialize()
          );
        }
      }

      // 封面图片上传
      $("#coverUrl")
        .fileinput({
          uploadUrl: ctx + "common/upload",
          allowedFileExtensions: ["jpg", "jpeg", "png", "gif", "bmp"],
          maxFileCount: 1,
          autoReplace: true,
          showUpload: false,
          uploadAsync: true,
        })
        .on("filebatchselected", function () {
          $(this).fileinput("upload");
        })
        .on("fileuploaded", function (event, data, previewId, index) {
          $("input[name='coverUrl']").val(data.response.fileName);
        })
        .on("fileremoved", function (event, id, index) {
          $("input[name='coverUrl']").val("");
        });

      // 视频文件上传
      $("#videoUrl")
        .fileinput({
          uploadUrl: ctx + "common/upload",
          maxFileCount: 1,
          autoReplace: true,
          showUpload: false,
          uploadAsync: true,
        })
        .on("filebatchselected", function () {
          $(this).fileinput("upload");
        })
        .on("fileuploaded", function (event, data, previewId, index) {
          $("input[name='videoUrl']").val(data.response.fileName);
        })
        .on("fileremoved", function (event, id, index) {
          $("input[name='videoUrl']").val("");
        });
    </script>
  </body>
</html>
